# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=farstream
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.2.9
pkgrel=1
pkgdesc="Farstream (formerly Farsight) - Audio/Video Communications Framework (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.freedesktop.org/wiki/Software/Farstream"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-libnice")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc")
source=(https://freedesktop.org/software/${_realname}/releases/${_realname}/${_realname}-${pkgver}.tar.gz{,.asc}
        farstream-make-4.3.patch::"https://gitlab.freedesktop.org/farstream/farstream/-/merge_requests/4.patch"
        0001-farstream-0.2.4.patch
        0002-give-cc-to-gir-scanner.all.patch)
sha256sums=('cb7d112433cf7c2e37a8ec918fb24f0ea5cb293cfa1002488e431de26482f47b'
            'SKIP'
            '036c2e3d410dd82dc43f04e457742f7b8048a3df18a22197b8e50c804c7fa011'
            '99107890e2eda2278cf100f8732d82c370a87318c7f27dedcde534fad63da7c8'
            'ceaa4e3699b607a87c0e8be80d548243c690ff00295b8f137624671ed6d11a81')
validpgpkeys=('DB30B086FAF86CE7296FADC51D388E5A4ED9A2BB') # Olivier Crête <olivier.crete@ocrete.ca>

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 --binary -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  
  apply_patch_with_msg \
    farstream-make-4.3.patch \
    0001-farstream-0.2.4.patch \
    0002-give-cc-to-gir-scanner.all.patch 

  WANT_AUTOMAKE=latest autoreconf --force --install
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --enable-introspection

  # Otherwise: libtool: error: cannot find the library 'libfarstream-0.2.la'
  make -j1
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  rm -f "${pkgdir}"${MINGW_PREFIX}/lib/gstreamer*/*.a
  rm -f "${pkgdir}"${MINGW_PREFIX}/lib/farstream*/*.a
}
